<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>发票登记列表</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">

                <span>发货人:</span>
                <div id="keyDeliveryCustomerId" name="keyDeliveryCustomerId"
                     class="mini-combobox"
                     style="width:300px;"
                     popupWidth="800" textField="name" valueField="id"
                     allowInput="true" required="false" requiredErrorText="发货人不能为空"
                     emptyText="发货人名称" >
                    <div property="columns">
                        <div header="发货人名称" field="name"></div>
                        <div header="发货人简称" field="shortName"></div>
                        <div header="发货人电话" field="phone"></div>
                        <div header="发货人地址" field="address"></div>
                    </div>
                </div>
                <span class="separator"></span>
                <span>分单号：</span>
                <input id="keyBillCode" name="keyBillCode" emptyText="请输入分单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="分单号不能为空" />
                <span>发票号：</span>
                <input id="keyInvoiceCode" name="keyInvoiceCode" emptyText="请输入发票号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="发票号不能为空" />
                <span class="separator"></span>
                <span>开票日期：</span>
                <input id="keyStartDate" name="keyStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyEndDate" name="keyEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>
                <span class="separator"></span>
                <span>发票类型:</span>
                <input id="keyInvoiceTypeId" name="keyInvoiceTypeId" class="mini-combobox" style="width:100px;" textField="name" valueField="id" emptyText="发票类型..."
                       required="false" allowInput="true" showNullItem="true" nullItemText="发票类型..." requiredErrorText="没有选择发票类型"/>
                <span class="separator"></span>
                <span>税率:</span>
                <input id="keyRateId" name="keyRateId" class="mini-combobox" style="width:100px;" textField="name" valueField="id" emptyText="税率..."
                       required="false" allowInput="true" showNullItem="true" nullItemText="税率..." requiredErrorText="没有选择税率"/>


                <div style="margin-top: 5px"></div>

                <% if(so.hasPermission("invoiceList:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
                <% } %>

                <% if(so.hasPermission("invoiceList:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <% if(so.hasPermission("invoiceList:setInvoiceCode")){%>
                    <span class="separator"></span>
                    <a class="mini-button" iconCls="icon-edit" onclick="showSaveInvoiceCode()">填写发票号码</a>
                <% } %>

                <% if(so.hasPermission("invoiceList:download")){%>
                    <span class="separator"></span>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="发票列表"/>
                <% } %>

            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/invoice_register/queryInvoiceDetailList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 allowResize="true"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 multiSelect = "true"
            >
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="nativeBillId" width="120" headerAlign="center" align="center" allowSort="true">分单号</div>
                    <div field="invoiceCode" width="120" headerAlign="center" align="center" allowSort="true">发票号</div>
                    <div field="deliveryCustomerId" width="200" headerAlign="center" align="left" allowSort="false"  data-options='{cacheName:"customer"}' renderer="commonRender">发货人名称</div>
                    <div field="openInvoiceCompanyId" width="200" headerAlign="center" align="left" allowSort="false"  data-options='{cacheName:"sysDic"}' renderer="commonRender">开票公司</div>
                    <div field="invoiceAmount" width="100" headerAlign="center" align="right" allowSort="false"  renderer="public_moneyRenderer">发票金额</div>
                    <div field="invoiceTitle" width="200" headerAlign="center" align="left" allowSort="false">发票抬头</div>
                    <div field="taxpayerIdentificationNumber" width="140" headerAlign="center" align="center" allowSort="true">纳税人识别号</div>
                    <div field="phoneNumber" width="100" headerAlign="center" align="center" allowSort="false"  renderer="commonDesensitization">电话</div>
                    <div field="invoiceAddress" width="200" headerAlign="center" align="left" allowSort="false">地址</div>
                    <div field="openAccountBankId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"bank"}' renderer="commonRender">开户银行</div>
                    <div field="bankAccount" width="140" headerAlign="center" align="center" allowSort="false" >银行账号</div>
                    <div field="invoiceTypeId" width="50" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">发票类型</div>
                    <div field="rateId" width="50" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">税率</div>
                    <div field="recipientName" width="140" headerAlign="center" align="left" allowSort="false" >收件人</div>
                    <div field="recipientPhone" width="140" headerAlign="center" align="center" allowSort="false" >收件人电话</div>
                    <div field="recipientAddress" width="140" headerAlign="center" align="left" allowSort="false" >收件人地址</div>

                    <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                    <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>

                </div>
            </div>
        </div>



        <div id="updateInvoiceCodePanel" class="mini-window" title="发票号设置" style="width:400px;height:200px;"
             showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
             showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
            <div property="footer" style="padding:10px;text-align: right">
                <a  class="mini-button" iconCls="icon-save" onclick="save()">保存</a>
                <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('updateInvoiceCodePanel')">关闭</a>
            </div>

            <div id="invoiceCodeForm">
                <input id="invoiceDetailIds" name="invoiceDetailIds" emptyText="请输入分单号"  class="mini-hidden" selectOnFocus="true" required="true" requiredErrorText="发票明细ID" />
                <span>发票号:</span>
                <input id="invoiceCode" name="invoiceCode" emptyText="请输入分单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="分单号不能为空" />
            </div>

        </div>



        <script type="text/javascript">
            mini.parse();

            let keyDeliveryCustomerId = mini.get("keyDeliveryCustomerId");
            let keyBillCode = mini.get("keyBillCode");
            let keyStartDate = mini.get("keyStartDate");
            let keyEndDate = mini.get("keyEndDate");
            let keyInvoiceTypeId = mini.get("keyInvoiceTypeId");
            let keyRateId = mini.get("keyRateId");

            // 主 grid
            let grid = mini.get("datagrid1");

            let queryForm = new mini.Form("#queryForm");


            let invoiceCodeForm = new mini.Form("#invoiceCodeForm");
            let invoiceDetailIds = mini.get("invoiceDetailIds");
            let invoiceCode = mini.get("invoiceCode");


            $(function (){
                let keyDeliveryCustomerIdJsonData = commonRenderDropList("customer");
                keyDeliveryCustomerId.load(keyDeliveryCustomerIdJsonData);

                let keyInvoiceTypeIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_INVOICE_TYPE");
                keyInvoiceTypeId.load(keyInvoiceTypeIdJsonData);

                let keyRateIdJsonData = commonRenderSysDicDropListByKey("sysDic", "XT_DIC_INVOICE_RATE");
                keyRateId.load(keyRateIdJsonData);

                grid.load();
            });


            function clearSearch(){
                queryForm.clear();
            }


            function search(){
                let data = queryForm.getData(true);
                grid.load(data);
            }


            function showSaveInvoiceCode(){
                let selectItems = grid.getSelecteds();
                if(selectItems.length == 0){
                    showAlert("请选择需要设置发票号的列表对象!");
                    return;
                }

                // invoiceCode
                let canCwInvoiceRegisterDetailId = "";

                for(let obj of selectItems){
                    canCwInvoiceRegisterDetailId += obj.detailId + ",";
                }

                if(canCwInvoiceRegisterDetailId.length == 0){
                    return;
                }

                invoiceDetailIds.setValue(canCwInvoiceRegisterDetailId.substr(0,canCwInvoiceRegisterDetailId.length-1));

                public_showModelAtPos("updateInvoiceCodePanel", "center", "middle");


            }


            //新增保存或修改保存
            function save(){
                // 添加并保存
                invoiceCodeForm.validate();
                if (invoiceCodeForm.isValid() == false){
                    public_showErrorTips("发票号没有填写！");
                    return;
                }
                let invoiceData = invoiceCodeForm.getData(true);

                mini.confirm("确定保存发票号？", "发票号保存",
                    function (action) {
                        if (action == "ok") {
                            let ret = public_getServerData("${base}/pages/finance_manage/invoice_register/detail/saveInvoiceCode",invoiceData);
                            showAlert(ret.message,function (){
                                if(ret.ok){
                                    public_onCancel("updateInvoiceCodePanel");
                                    grid.reload();
                                }
                            });
                        }
                    }
                );
            }



        </script>



    </body>
</html>